#!/usr/bin/php -q
<?php
//need to make sure this is correct as well, depending on where the file is stored.
include 'includes/config.php';

$dbuser = $killD->uname;
$dbpwd = $killD->pass;
$dbname = $killD->db;

////////////////////////////////////////////////////////////////////////

function db_query($q){
	//     on -->   failure     no-match    match
	// return -->   FALSE       TRUE        array

	$ra = array();
	if($ro = mysql_query($q)){
		if(!is_resource($ro)) return 1;
		while($row = mysql_fetch_row($ro)) $ra[] = $row;
		mysql_free_result($ro);
	} else {
		printf("database query failed: %s<br>", mysql_error());
	}
	if(count($ra) == 0) return 0; else return $ra;
}

////////////////////////////////////////////////////////////////////////

mysql_connect($killD->localhost, $dbuser, $dbpwd)
	or die("could not connect to database: ". mysql_error());
mysql_select_db($dbname);

$t = time();
$parts = getdate($t);
$today = $t - ($parts['seconds'] + $parts['minutes']*60 + $parts['hours']*3600);
$sixmonths = $today - 16070400; // six months ago

db_query("DELETE FROM kills WHERE timestamp < $sixmonths;");

mysql_close();
?>
